interface WriteInterface {
    text:string;//文字描述
    className?:string;//class 类
    style?:{};//style样式
    id?:string;//id
    element:string;//元素节点
}

class Write {
    constructor(props:WriteInterface) {
        Write.writeInfo = props;
        this.write();
    }
    static writeInfo:WriteInterface;
    write = () =>{
        const {text,style,className,id,element} = Write.writeInfo;
        let writeHead = `<${element}`;
        if(style){
            let styleStr = '';
            let styles = JSON.parse(JSON.stringify(style));
            for(let key in styles){
                let str = styles[key];
                styleStr = `${styleStr}${key}:${str};`
            }
            writeHead = `${writeHead} style=${styleStr}`
        }
        if (className){
            writeHead = `${writeHead} class=${className}`
        }
        if(id){
            writeHead = `${writeHead} id=${id}`
        }
        document.write(`${writeHead}>${text}</${element}>`)
    }
}

interface WriteElementInterface {
    text:string;//写入的文字信息
    className?:string;//css 样式类
    style?:{};//style样式
    id?:string;//id

}

/**
 * span标签
 */
class WriteSpan {
    constructor(props: WriteElementInterface) {
        let props_ = JSON.parse(JSON.stringify(props));
        props_.element = 'span';
        new Write(props_)
    }
}

/**
 * H标签
 */
class WriteH {
    constructor(props:WriteElementInterface,number:number = 1) {
        let props_ = JSON.parse(JSON.stringify(props));
        props_.element = `h${number}`;
        new Write(props_);
    };
}

/**
 * div标签
 */
class WriteDiv {
    constructor(props: WriteElementInterface) {
        let props_ = JSON.parse(JSON.stringify(props));
        props_.element = 'div';
        new Write(props_)
    }
}

/**
 * span标签写入
 * @param span
 */
const writeSpan = (span:WriteElementInterface) =>{
  new WriteSpan(span)
};
/**
 * h标签的写入
 * @param h H标签的信息
 * @param number  第几号标签 默认 1，范围1-6
 */
const writeH = (h:WriteElementInterface,number:number = 1) =>{
    new WriteH(h,number);
};

/**
 * div标签写入
 * @param div
 */
const writeDiv = (div:WriteElementInterface) =>{
    new WriteDiv(div)
};
